/*     */ package nc.bs.ecn.eco.rule;
/*     */ 
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import nc.bs.ecn.eco.adapter.EcoBomServiceAdapter;
/*     */ import nc.bs.framework.common.NCLocator;
/*     */ import nc.bs.pubapp.AppBsContext;
/*     */ import nc.impl.pubapp.pattern.data.vo.VOUpdate;
/*     */ import nc.impl.pubapp.pattern.rule.IRule;
/*     */ import nc.itf.bd.bom.bom0202.IBomBillQueryService;
/*     */ import nc.util.mmf.framework.base.MMArrayUtil;
/*     */ import nc.util.mmf.framework.base.MMStringUtil;
/*     */ import nc.util.mmf.framework.base.MMValueCheck;
/*     */ import nc.vo.bd.bom.bom0202.entity.AggBomVO;
/*     */ import nc.vo.bd.bom.bom0202.entity.BomActivityVO;
/*     */ import nc.vo.bd.bom.bom0202.entity.BomOutputsVO;
/*     */ import nc.vo.bd.bom.bom0202.entity.BomUseOrgVO;
/*     */ import nc.vo.bd.bom.bom0202.entity.BomVO;
/*     */ import nc.vo.bd.bom.bom0202.enumeration.FBomBillstatusEnum;
/*     */ import nc.vo.bd.bom.bom0202.paramvo.ecn.BomParamForEcoPublishRewrite;
/*     */ import nc.vo.ecn.eco.entity.AggEcoVO;
/*     */ import nc.vo.ecn.eco.entity.EcoItemVO;
/*     */ import nc.vo.ecn.eco.entity.EcoVO;
/*     */ import nc.vo.ecn.eco.enumeration.FChangeIdentityEnum;
/*     */ import nc.vo.ecn.eco.enumeration.FChangeTypeEnum;
/*     */ import nc.vo.ecn.eco.param.EcoChangeBOMParam;
/*     */ import nc.vo.ecn.eco.util.EcoUtil;
/*     */ import nc.vo.pub.BusinessException;
/*     */ import nc.vo.pubapp.pattern.exception.ExceptionUtils;
/*     */ 
/*     */ 
/*     */ 
/*     */ public class EcoGenerateBomRule
/*     */   extends Object
/*     */   implements IRule<AggEcoVO>
/*     */ {
/*     */   public void process(AggEcoVO[] vos) {
/*  38 */     if (MMValueCheck.isEmpty(vos)) {
/*     */       return;
/*     */     }
/*  41 */     List<AggBomVO> list = new ArrayList<AggBomVO>();
/*  42 */     for (AggEcoVO vo : vos) {
/*  43 */       EcoVO ecohead = (EcoVO)vo.getParent();
/*  44 */       EcoChangeBOMParam[] params = EcoUtil.setEcoPublishParam(vo);
/*  45 */       for (EcoChangeBOMParam param : params) {
/*  46 */         AggBomVO aggvo = EcoUtil.changeTOBom(param);
/*     */ 
/*     */         
/*  49 */         BomVO bomVO = (BomVO)aggvo.getParent();
/*     */         
/*  51 */         bomVO.setAttributeValue("fbillstatus", FBomBillstatusEnum.APPROVE.value());
/*     */         
/*  53 */         bomVO.setAttributeValue("taudittime", AppBsContext.getInstance().getServerTime());
/*     */         
/*  55 */         bomVO.setAttributeValue("approver", ecohead.getApprover());
/*     */         
/*  57 */         AggBomVO changedBom = new AggBomVO();
/*  58 */         if (MMStringUtil.isNotEmpty(param.getAfterChangeVO().getVbomversion())) {
/*     */           
/*     */           try {
/*     */             
/*  62 */             changedBom = ((IBomBillQueryService)NCLocator.getInstance().lookup(IBomBillQueryService.class)).queryAggBomByBomID(new String[] {
/*  63 */                   param.getBeforeChangeVO().getVbomversion()
/*     */                 })[0];
/*     */           }
/*  66 */           catch (BusinessException e) {
/*  67 */             ExceptionUtils.wrappException(e);
/*     */           } 
/*     */         }
/*     */ 
/*     */         
/*  72 */         BomUseOrgVO[] useorgs = new BomUseOrgVO[0];
/*  73 */         if (MMValueCheck.isNotEmpty(changedBom.getParent())) {
/*  74 */           useorgs = (BomUseOrgVO[])((BomUseOrgVO[])changedBom.getChildren(BomUseOrgVO.class)).clone();
/*     */         }
/*  76 */         if (FChangeTypeEnum.NEW.equalsValue(Integer.valueOf(param.getChangeType()))) {
/*     */           
/*  78 */           if (!ecohead.getBcreateversion().booleanValue()) {
/*  79 */             BomUseOrgVO useorg = new BomUseOrgVO();
/*  80 */             useorg.setPk_useorg(ecohead.getPk_org());
/*  81 */             useorg.setStatus(2);
/*  82 */             aggvo.setChildren(BomUseOrgVO.class, new BomUseOrgVO[] { useorg });
/*     */           
/*     */           }
/*     */           else {
/*     */ 
/*     */             
/*  88 */             if (MMArrayUtil.isNotEmpty(useorgs)) {
/*  89 */               for (BomUseOrgVO useorg : useorgs) {
/*  90 */                 useorg.setPk_bom_useorg(null);
/*  91 */                 useorg.setCbomid(null);
/*  92 */                 useorg.setStatus(2);
/*     */               } 
/*  94 */               aggvo.setChildren(BomUseOrgVO.class, useorgs);
/*     */             } else {
/*     */               
/*  97 */               BomUseOrgVO useorg = new BomUseOrgVO();
/*  98 */               useorg.setPk_useorg(ecohead.getPk_org());
/*  99 */               useorg.setStatus(2);
/* 100 */               aggvo.setChildren(BomUseOrgVO.class, new BomUseOrgVO[] { useorg });
/*     */             } 
/*     */ 
/*     */             
/* 104 */             BomOutputsVO[] outputs = (BomOutputsVO[])changedBom.getChildren(BomOutputsVO.class);
/* 105 */             if (MMArrayUtil.isNotEmpty(outputs)) {
/* 106 */               for (BomOutputsVO outputvo : outputs) {
/* 107 */                 outputvo.setCbom_outputsid(null);
/* 108 */                 outputvo.setCbomid(null);
/* 109 */                 outputvo.setStatus(2);
/*     */               } 
/* 111 */               aggvo.setChildren(BomOutputsVO.class, outputs);
/*     */             } 
/* 113 */             BomActivityVO[] actvos = (BomActivityVO[])changedBom.getChildren(BomActivityVO.class);
/* 114 */             if (MMArrayUtil.isNotEmpty(actvos)) {
/* 115 */               for (BomActivityVO actvo : actvos) {
/* 116 */                 actvo.setCbom_activityid(null);
/* 117 */                 actvo.setCbomid(null);
/* 118 */                 actvo.setStatus(2);
/*     */               } 
/* 120 */               aggvo.setChildren(BomActivityVO.class, actvos);
/*     */             }
/*     */           
/*     */           } 
/* 124 */         } else if (MMArrayUtil.isEmpty(aggvo.getChildren(BomUseOrgVO.class)) && MMArrayUtil.isNotEmpty(useorgs)) {
/* 125 */           for (BomUseOrgVO useorg : useorgs) {
/* 126 */             useorg.setStatus(1);
/*     */           }
/* 128 */           aggvo.setChildren(BomUseOrgVO.class, useorgs);
/*     */         } 
/* 130 */         list.add(aggvo);
/*     */       } 
/*     */     } 
/*     */     
/*     */     try {
/* 135 */       BomParamForEcoPublishRewrite[] params = EcoBomServiceAdapter.generateBom((AggBomVO[])list.toArray(new AggBomVO[list.size()]));
/*     */       
/* 137 */       setItemUpdate(vos[0], params[0]);
/*     */     }
/* 139 */     catch (BusinessException e) {
/* 140 */       ExceptionUtils.wrappException(e);
/*     */     } 
/*     */   }
/*     */   
/*     */   private void setItemUpdate(AggEcoVO aggVO, BomParamForEcoPublishRewrite param) {
/* 145 */     if (MMValueCheck.isEmpty(aggVO) && MMValueCheck.isEmpty(param)) {
/*     */       return;
/*     */     }
/* 148 */     EcoVO parent = (EcoVO)aggVO.getParent();
/* 149 */     EcoItemVO[] items = aggVO.getChildrenVO();
/* 150 */     for (EcoItemVO item : items) {
/* 151 */       item.setPk_eco(parent.getPk_eco());
/* 152 */       if (FChangeIdentityEnum.AFTERCHANGE.equalsValue(item.getFbchangenote())) {
/* 153 */         item.setVbomversion(param.getCbomid());
/* 154 */         item.setBbpulished(param.getHaspublished());
/* 155 */         item.setTlastreleasetime(param.getPublishDate());
/* 156 */         item.setHversion(param.getHversion());
/* 157 */         item.setFbomstatus(Integer.valueOf(param.getFbomstatus()));
/* 158 */         item.setBomapprover(param.getBomapprover());
/* 159 */         item.setBomaudittime(param.getBomaudittime());
/*     */       } 
/*     */     } 
/*     */     
/* 163 */     VOUpdate<EcoItemVO> update = new VOUpdate<EcoItemVO>();
/* 164 */     update.update(items);
/*     */   }
/*     */ }


/* Location:              E:\zhuhai_ncc\NCC2111\modules\mmecn\META-INF\lib\mmecn_eco.jar!/nc/bs/ecn/eco/rule/EcoGenerateBomRule.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.0.7
 */